﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Imaginecup.Recycling.Object;
using Imaginecup.Engine;

namespace Imaginecup.recycling.Object.Entity
{
    public class ObjectInfo
    {
        private Vector2 worldLocation;
        private int frameWidth;
        private int frameHeight;
        private Rectangle collisionRect;
        private Rectangle m_ImageRect;

        public ObjectInfo(Rectangle _collisionRect)
        {
            worldLocation = new Vector2(_collisionRect.X, _collisionRect.Y);
            collisionRect = _collisionRect;
            frameWidth = _collisionRect.Width;
            frameHeight = _collisionRect.Height;

            m_ImageRect = new Rectangle(0, 0, frameWidth, frameHeight);
        }
        public ObjectInfo(Vector2 _position, int width, int height)
        {
            worldLocation = _position;
            collisionRect = new Rectangle((int)worldLocation.X, (int)worldLocation.Y, width, height);
        }

        public ObjectInfo(Vector2 _position, Rectangle _collisionRect)
        {
            worldLocation = _position;
            collisionRect = _collisionRect;
        }

        public void SetPositionX(float x)
        {
            worldLocation.X = x;
        }
        public void SetPositionY(float y)
        {
            worldLocation.Y = y;
        }
        #region Properties
        // 그림 크기에 특정 크기를 더해서 충돌 좌표 생성
        public Rectangle CollisionRectangle
        {
            get
            {
                return new Rectangle(
                    (int)worldLocation.X + collisionRect.X,
                    (int)worldLocation.Y + collisionRect.Y,
                    collisionRect.Width,
                    collisionRect.Height);
            }
            set { collisionRect = value; }
        }

        public Rectangle SourceRectangle
        {
            get { return collisionRect; }
        }

        public int FrameWidth
        {
            get { return frameWidth; }
            set { frameWidth = value;}
        }

        public int FrameHeight
        {
            get { return frameHeight; }
            set { frameHeight = value; }
        }

        public Rectangle WorldRectangle
        {
            get
            {
                return new Rectangle(
                    (int)worldLocation.X,
                    (int)worldLocation.Y,
                    frameWidth,
                    frameHeight);
            }
        }

        public Rectangle ScreenRectangle
        {
            get
            {
                return Camera.WorldToScreen(WorldRectangle);
            }
        }
        public Rectangle ImageRectangle
        {
            get { return m_ImageRect; }
            set { m_ImageRect = value; }
        }
        public void SetImageRectByRatio(int ratio)
        {
            m_ImageRect.Y = frameHeight - ratio;
            m_ImageRect.Height = ratio;
            worldLocation.Y = SourceRectangle.Y + frameHeight - ratio;
        }

        public Vector2 WorldLocation
        {
            get { return worldLocation ; }
            set { worldLocation = value; }
        }

        public Vector2 RelativeCenter
        {
            get { return new Vector2(FrameWidth / 2, FrameHeight / 2); }
        }

        public Vector2 WorldCenter
        {
            get { return worldLocation + RelativeCenter; }
        }

        public Vector2 ScreenCenter
        {
            get
            {
                return Camera.WorldToScreen(worldLocation + RelativeCenter);
            }
        }
        #endregion

    }
}
